﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace PocketMahjong.Core
{
	public struct Position
	{
		private int _row;
		public int Row
		{
			get { return _row; }
			set { _row = value; }
		}

		private int _column;
		public int Column
		{
			get { return _column; }
			set { _column = value; }
		}

		private int _layer;
		public int Layer
		{
			get { return _layer; }
			set { _layer = value; }
		}

		public static bool operator ==(Position a, Position b)
		{
			return a.Layer == b.Layer && a.Row == b.Row && a.Column == b.Column;
		}

		public static bool operator !=(Position a, Position b)
		{
			return !(a == b);
		}

		public Position(int layer, int row, int column)
		{
			_layer = layer;
			_row = row;
			_column = column;
		}

		public override string ToString()
		{
			return string.Format("[{0},{1},{2}]", Layer, Row, Column);
		}

		public void Write(Stream stream)
		{
			stream.WriteByte((byte)_layer);
			stream.WriteByte((byte)_row);
			stream.WriteByte((byte)_column);
		}

		public static Position Read(Stream stream)
		{
			var lay = stream.ReadByte();
			var row = stream.ReadByte();
			var col = stream.ReadByte();
			return new Position(lay, row, col);
		}
	}
}
